import axios from "axios";
const searchModule ={
    state:{
        searchCountry:[],
        tripId:"",
        searchDetail:{},
        indexDetail:{},
        arrInd:6
    },
    mutations:{
        setSearchTrip:function(state,value){
            // console.log(value)
            state.searchCountry=value.list;
            // console.dir(state.searchCountry)
            state.tripId=value._id;
            // console.log(state.tripId)
        },
        // 每条路线详情
        setSearchDetail:function(state,value){
            state.searchDetail = value
        },
        // 首页每条路线详情
        setIndexDetail:function(state,value){
            state.indexDetail=value
        }
    },
    actions:{
        // 根据搜索的城市名字请求数据
        reqestCountryTrip(state,data){
            // console.log(123)
            // console.log(data)
            axios.get("api/searchTrip",{params:{countryName:data}})
            .then(res=>{
                // console.dir(res.data.msg)
                state.commit("setSearchTrip",res.data.msg)
            })
        },
        // 搜索城市旅游路线的详细情况
        requestTripDetail(state,data){
            // console.log(data)
            axios.post("/api/searchDetail",{data})
            .then(res=>{
                // console.dir(res.data.msg)
                state.commit("setSearchDetail",res.data.msg)
            })
        },
        // 首页某个路径的详细信息
        requestIndexDetail(state,data){
            // console.log(data)
            axios.post("/api/indexDetail",{data})
            .then(res=>{
                // console.log(res.data.msg);
                state.commit("setIndexDetail",res.data.msg)
            })
        }
    }
}

export default searchModule;